/**
 * Created by mapbar_front on 2019/7/5.
 */
import React,{ Component } from 'react';
import target from './Utils';
class Brother extends Component{
    constructor(props){
        super(props);
        this.state = {
            str:'',
        }
    }
    componentDidMount(){
        // target.addHandler('message',(str)=>{
        //     this.setState({
        //         str,
        //     })
        // })

        console.log('BrotherB',new Date().getTime());
        //这里为何不能这样写呢？
        var that = this;
        target.addHandler('message',function(str){
            console.log('this',this);
            that.setState({
                str,
            })
        })
    }
    render(){
        return(
            <div>
                BrotherB,{ this.props.str }
                <h2>得到兄弟A,{ this.state.str }</h2>
            </div>
        )
    }
}
export default Brother;